home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlb20 / lib / statfs.c < prev    next >
C/C++ Source or Header  |  1992-03-10  |  1KB  |  70 lines

  1. /*
  2.  * statfs() emulation for MiNT/TOS
  3.  *
  4.  * Written by Adrian Ashley (adrian@secret.uucp)
  5.  * and placed in the public domain.
  6.  */
  7.  
  8. #include <errno.h>
  9. #include <stat.h>
  10. #include <osbind.h>
  11. #include <sys/statfs.h>
  12.  
  13. int statfs(path, buf)
  14.   char *path;
  15.   struct statfs *buf;
  16. {
  17.   int r;
  18.   struct {
  19.     unsigned long free_blocks, total_blocks, sector_size, sec_per_block;
  20.   } free;
  21.   struct stat statbuf;
  22.  
  23.   if (!buf || !path)
  24.   {
  25.     errno = EFAULT;
  26.     return -1;
  27.   }
  28.  
  29.   r = stat(path, &statbuf);
  30.  
  31.   if (r == -1)
  32.     return -1;
  33.  
  34.   (void) Dfree(&free, statbuf.st_dev + 1);
  35.  
  36.   buf->f_type = 0;
  37.   buf->f_bsize = free.sector_size * free.sec_per_block;
  38.   buf->f_blocks = free.total_blocks;
  39.   buf->f_bfree = buf->f_bavail = free.free_blocks;
  40.   buf->f_files = buf->f_ffree = buf->f_fsid.val[0] = buf->f_fsid.val[1] = -1L;
  41.  
  42.   return 0;
  43. }
  44.  
  45. #ifdef TEST
  46.  
  47. #include <stdio.h>
  48.  
  49. main(int argc, char **argv)
  50. {
  51.   int i = 0, r;
  52.   register char *p;
  53.   struct statfs stbuf;
  54.  
  55.   while (--argc)
  56.   {
  57.     p = argv[++i];
  58.  
  59.     r = statfs(p, &stbuf);
  60.     if (r == -1)
  61.       perror(p);
  62.     else
  63.       printf("statfs(`%s'): %ld free bytes\n", p,
  64.     (long)(stbuf.f_bfree * stbuf.f_bsize));
  65.   }
  66.   return 0;
  67. }
  68.  
  69. #endif
  70.